//===========================虚拟供应商报价-inventedVendorQuotatio.js


//请求寻源应用路由
let quotationServicePath = "/api/launcher/sourcingcenter/application/invoke?action=/QuotationService";
const quotationRoute = {
    "notInvolved": quotationServicePath + "/notInvolved",
    "batchParticipation": quotationServicePath + "/batchParticipation",
    "clarifyRecord": quotationServicePath + "/clarifyRecord",
    "updateQuotation": quotationServicePath + "/updateQuotation",
    "amountCalculation": quotationServicePath + "/amountCalculation",
    "batchCommit": quotationServicePath + "/batchCommit",
    "counterPrice": quotationServicePath + "/counterPrice"
}


// 创建报价列表特定字段可编辑
const updateQuotationKeyId = ["expire", "pretax_price", "delivery", "address", "description", "attachment", "name", "brand", "model", "num", "unit",
    "package_num", "package_unit", "freight", "tax_rate_freight", "platform_category_name", "spec", "sku", "bar_code"];
const requiredQuotationKeyId = ["expire", "pretax_price", "delivery", "address", "name", "brand", "model", "num", "unit", "tax_rate_freight"];
// 创建报价列表id
var quotationFormListId = 'FormList14';

//询价商品状态样式
const InquiryGoodsStatusMap = {
    '新建': '#52C419',
    '审核中': '#1890FF',
    '已退回': '#F5222D',
    '报价中': '#d9d9d9',
    '已结束': '#FAAD15',
    '已关闭': '#1890FF'
};
//报价商品状态样式
const quotationGoodsStatusArr = ['#52C419', '#F5222D', '#F5222D', '#FAAD15', '#FAAD15', '#1890FF', '#d9d9d9', '#d9d9d9'];


//询价单列表字段样式
const InquiryStyle = ["ModelTableColumn214", "ModelTableColumn174", "ModelTableColumn28", "ModelTableColumn45", "ModelTableColumn66", "ModelTableColumn87", "ModelTableColumn109", "ModelTableColumn131", "ModelTableColumn151"];
//询价商品列表字段样式
const GoodsStyle = ["ModelTableColumn215", "ModelTableColumn175", "ModelTableColumn43", "ModelTableColumn68", "ModelTableColumn67", "ModelTableColumn88", "ModelTableColumn110", "ModelTableColumn132", "ModelTableColumn152"];
//询价商品状态列表字段样式
const GoodsStatus = ["ModelTableColumn5", "ModelTableColumn29", "ModelTableColumn112", "ModelTableColumn154"];
//报价商品状态列表字段样式
const QuotationStatus = ["ModelTableColumn31", "ModelTableColumn69", "ModelTableColumn89", "ModelTableColumn111", "ModelTableColumn133", "ModelTableColumn153"];
//


// 封装了axiosService 方便调用其他应用的服务
const axiosService = function (url, param) {
    return new Promise(function (resolve, reject) {
        h3ui.axios({
            method: 'post',
            url,
            data: param,
            headers: {
                Authorization: 'Bearer ' + localStorage.getItem("token"),
                'Content-Type': 'application/json;charset=UTF-8'
            }
        }).then(function (res) {
            console.log(res);

            if (res.status == 200) {
                resolve(res.data);
            } else {
                reject(res);
            }
        }).catch(function (error) {
            h3ui.$message.error(error);
        });
    })
}


const Operator = {
    EQ: 'EQ',
    NOT_EQ: 'NOT_EQ',
    LIKE: 'LIKE',
    GT: 'GT',
    LT: 'LT',
    GTE: 'GTE',
    LTE: 'LTE',
    IN: 'IN',
    NOT_IN: 'NOT_IN',
    NOT_LIKE: 'NOT_LIKE',
    IS_NULL: 'IS_NULL',
    IS_NOT_NULL: 'IS_NOT_NULL'
}


//获取系统加载列表服务
function customConditionLoad(evt, custCondArr, custListBo) {
    let {pageIndex, pageSize, filter} = evt.data;

    let listId = evt.node.id;
    let schemaCode = h3ui.widgets[listId].props.bindingModel.schemaCode;
    let dataSource = h3ui.models[schemaCode];
    filter = JSON.parse(JSON.stringify(filter)) || {};

    let condition = dataSource.toQueryCondition(filter, dataSource.schema);

    if (custCondArr) {
        if (!condition) {
            condition = {conditions: [], nature: "AND"};
        }

        condition.conditions = condition.conditions.concat(custCondArr);
    }

    let param = {
        condition: condition,
        currentLevel: false,
        displayColumn: {},
        page: pageIndex,
        pageIndex: pageIndex - 1,
        pageSize: pageSize,
        schemaCode: schemaCode,
        size: pageSize,
        tree: false,
    }

    let doService;
    // 是否调用系统的listBo
    if (custListBo) {
        h3ui.services[custListBo](param).then(res => {
            if (res.success) {
                h3ui.models[schemaCode].loadItemsRefProp(res.data.data);

                h3ui.$message.loading("数据加载中...", 0.5, function () {
                    h3ui.widgets[listId].props.dataSource = {
                        items: res.data.data,
                        total: res.data.total
                    }
                });

            }
        })
    } else {
        let url = "/api/launcher/" + h3ui.appInfo.appCode + "/application/invoke?action=/ApplicationService/listBO";
        axiosService(url, param).then(res => {
            if (res.success) {
                h3ui.models[schemaCode].loadItemsRefProp(res.data.data);
                h3ui.widgets[listId].props.dataSource = {
                    items: res.data.data,
                    total: res.data.total
                }
            }
        })
    }


}

//页面初始化
function pageInit() {
    inquiryExpireTimeInit();
}

//询价截止时间初始化
function inquiryExpireTimeInit() {
    // 未报价的查询条件初始化询价截止时间范围 ,大于当前时间

    var formItemIds = ["FormModelItem136", "FormModelItem134"];

    formItemIds.forEach(a => {
        var exprProps = h3ui.widgets[a].props
        exprProps.value = [new Date(), new Date("3090-12-12")];
    })


}


//触发列表刷新事件
function reloadList(fromListId) {
    doReloadList({pageIndex: 1, node: {id: fromListId}});
}

//列表刷新
function doReloadList(evt) {
    var list = h3ui.widgets[evt.node.id];


    list.emit("load", queryListParam(list));


    list.props.selectedRowKeys = [];
    list.props.selectedRow = [];

}

function queryListParam(list) {
    var queryId = list.childIds.find(a => a.includes("ModelQueryForm"));

    var filter = h3ui.widgets[queryId].props.value || {};

    filter = JSON.parse(JSON.stringify(filter));

    var pageId = list.childIds.find(a => a.includes("Pagination"));

    var pageIndex = h3ui.widgets[pageId].props.current;
    var pageSize = h3ui.widgets[pageId].props.pageSize;

    return {pageIndex, pageSize, filter};
}


//===================未参与报价 tab ==========================

//未报价列表加载事件
function inventedNotInvolvedList(evt) {

    // var listId = "FormList4";

    // var list = h3ui.widgets[listId];

    // var param = queryListParam(list);

    // var organization_id = h3ui.widgets.Input20.props.organization_id;

    // if(organization_id && organization_id.length>0){
    //     param.filter.organization_id = organization_id;
    // }

    // var pageIndex = param.pageIndex;
    // var pageSize = param.pageSize;

    // var filter = param.filter;
    // if(filter.inquiry_id ){
    //     filter.inquiry_id = filter.inquiry_id.join();
    // }

    // param = Object.assign({pageIndex,pageSize},filter);

    // axiosService(quotationRoute.notInvolved,param).then(res=> {
    //     if(res.success){
    //         var resItem = res.data;
    //         // 列表中有关联模型，需要使用以下方法触发
    //         h3ui.models.t_inquiry_goods.loadItemsRefProp(resItem.data);
    //         list.props.dataSource =  {items : resItem.data, total:  resItem.total}   ;
    //     }else{
    //         h3ui.$message.error(res.errMessage ||  '获取列表失败');
    //     }
    // })


    console.log(evt);
    let {pageIndex, pageSize, filter} = evt.data;

    let listId = evt.node.id;
    var list = h3ui.widgets[listId];
    let schemaCode = h3ui.widgets[listId].props.bindingModel.schemaCode;
    let dataSource = h3ui.models[schemaCode];
    filter = JSON.parse(JSON.stringify(filter)) || {};

    //  momo过渡字段值设置为空
    filter.memo = "";


    let condition = dataSource.toQueryCondition(filter, dataSource.schema);

    //虚拟供应商的id
    var organization_id = h3ui.widgets.Input20.props.organization_id;
    if (organization_id) {
        condition.conditions.push({field: "vendor_organization_id", operator: Operator.EQ, value: organization_id});
    }

    let listQuery = {
        condition: condition,
        currentLevel: false,
        displayColumn: {},
        page: pageIndex,
        pageIndex: pageIndex - 1,
        pageSize: pageSize,
        schemaCode: schemaCode,
        size: pageSize,
        tree: false,
    }

    h3ui.services.inventedNotInvolved(listQuery).then(res => {
        if (res.success) {
            var resItem = res.data;
            // 列表中有关联模型，需要使用以下方法触发
            h3ui.models.t_inquiry_goods.loadItemsRefProp(resItem.data);
            list.props.dataSource = {items: resItem.data, total: resItem.total};
        } else {
            h3ui.$message.error(res.errMessage || '获取列表失败');
        }
    })


}

// 打开选择供应商弹框
function openSelectVendorModal(evt) {
    console.log(evt);

    h3ui.widgets.CustomModal1.props.visible = true;
    h3ui.widgets.Input20.props.disabled = true;// 必须失效,否则弹框关不了

    setTimeout(function () {
        h3ui.widgets.Input20.props.disabled = false;
    }, 3000);
}

//点击选择供应商
function selectVendor(evt) {
    console.log(evt);


    debugger;

    var organization = evt.data.row.organization_id;


    if (!organization || organization.length == 0) {
        h3ui.$message.warn('数据错误,供应商不能为空');
        return;
    }


    h3ui.widgets.Input20.props.value = organization[0].name;
    h3ui.widgets.Input20.props.organization_id = organization[0];


    h3ui.widgets.CustomModal1.props.visible = false;
    h3ui.widgets.Input20.props.disabled = false;

    reloadList("FormList4");

}

//未参与列表 选择供应商查询条件 值变化事件
function vendorValueChange(evt) {
    console.log(evt);

    if (!evt.data.value) {
        h3ui.widgets.Input20.props.organization_id = null;
    }

}


//批量参与
function batchPartake(evt) {

    debugger;

    var listId = "FormList4";
    var list = h3ui.widgets[listId];

    var keys = list.props.selectedRowKeys;

    if (keys.length == 0) {
        h3ui.$message.info("请勾选一行数据");
        return;
    }

    var organization_id = h3ui.widgets.Input20.props.organization_id;

    if (!organization_id || organization_id.length == 0) {
        h3ui.$message.info("请选择供应商");
        return;
    }


    h3ui.$confirm({
        title: '确定参与报价?',
        onOk() {

            var param = {inquiryGoodsIdList: keys, organization_id: organization_id, isVirtual: false};

            axiosService(quotationRoute.batchParticipation, param).then(res => {
                if (res.success) {
                    h3ui.$message.info('提交成功');
                    reloadList(listId);
                } else {
                    h3ui.$message.error(res.errMessage || '提交失败');
                }
            })
        }
    });

}


const inquiryFormShow = ['ModelTableColumn28', 'ModelTableColumn45', 'ModelTableColumn109', 'ModelTableColumn87', 'ModelTableColumn66', 'ModelTableColumn131', 'ModelTableColumn151'];
const inquiryGoodsFormShow = ['ModelTableColumn43', 'ModelTableColumn68', 'ModelTableColumn110', 'ModelTableColumn88', 'ModelTableColumn67', 'ModelTableColumn132', 'ModelTableColumn152'];


// 行单机事件
function rowClick(evt) {

    // 询价单信息
    if (inquiryFormShow.includes(evt.data.col.node.id)) {
        h3ui.models.t_inquiry.newItem();
        // 加载询价单数据
        let bizObjectId = evt.data.row.inquiry_id;
        h3ui.models.t_inquiry.loadBO({bizObjectId: bizObjectId}).then(res => {
            if (res) {
                h3ui.widgets.Modal9.props.visible = true;
            }
        });
    } else if (inquiryGoodsFormShow.includes(evt.data.col.node.id)) {
        h3ui.models.t_inquiry_goods.newItem();
        // 加载询价商品数据
        let bizObjectId = evt.data.row.inquiry_goods_id[0].id;
        h3ui.models.t_inquiry_goods.loadBO({bizObjectId: bizObjectId}).then((res) => {
            if (res) {
                h3ui.widgets.Modal2.props.visible = true;
                clarifyRecord(bizObjectId);
            }
        });
    }

}


// 操作列事件
function actionColumn(evt) {
    console.log(evt);
    // 待参与
    if ("FormList4" == evt.node.id) {
        if ('详情' == evt.data.action) {
            // 打开询价商品详情
            h3ui.widgets.Modal2.props.visible = true;
            // 加载询价商品数据
            let bizObjectId = evt.data.row.id;
            h3ui.models.t_inquiry_goods.loadBO({bizObjectId: bizObjectId}).then(() => {
                clarifyRecord(bizObjectId);
            });
        }
    } else if ('FormList6' == evt.node.id) {// 待报价

    } else if ('FormList7' == evt.node.id) { //未提交
        if ('详情' == evt.data.action) {
            // 打开报价商品详情
            h3ui.widgets.Modal10.props.visible = true;
            // 加载报价商品数据
            let bizObjectId = evt.data.row.id;
            h3ui.models.t_quotation_goods.loadBO({bizObjectId: bizObjectId}).then();
        }
    } else if ('FormList11' == evt.node.id) { //已报价
        if ('详情' == evt.data.action) {
            // 打开报价商品详情
            h3ui.widgets.Modal10.props.visible = true;
            // 加载报价商品数据
            let bizObjectId = evt.data.row.id;
            h3ui.models.t_quotation_goods.loadBO({bizObjectId: bizObjectId}).then();
        }
    } else if ('FormList10' == evt.node.id) { // 已还价价
        if ('详情' == evt.data.action) {
            // 打开报价商品详情
            h3ui.widgets.Modal10.props.visible = true;
            // 加载报价商品数据
            let bizObjectId = evt.data.row.id;
            h3ui.models.t_quotation_goods.loadBO({bizObjectId: bizObjectId}).then();
        } else if ('再次报价' == evt.data.action) {

            h3ui.models.t_quotation_goods.newItem();
            // 设置报价id
            h3ui.models.t_quotation_goods.item.id = evt.data.row.id;
            // 打开对话框
            h3ui.widgets.Modal11.props.visible = true;
        }
    } else if ('FormList8' == evt.node.id) {// 已定标

        if ('详情' == evt.data.action) {
            // 打开报价商品详情
            h3ui.widgets.Modal10.props.visible = true;
            // 加载报价商品数据
            let bizObjectId = evt.data.row.id;
            h3ui.models.t_quotation_goods.loadBO({bizObjectId: bizObjectId}).then();
        }
    } else if ('FormList12' == evt.node.id) {//已关闭

        if ('详情' == evt.data.action) {
            // 打开报价商品详情
            h3ui.widgets.Modal10.props.visible = true;
            // 加载报价商品数据
            let bizObjectId = evt.data.row.id;
            h3ui.models.t_quotation_goods.loadBO({bizObjectId: bizObjectId}).then();
        }
    } else if ('FormList13' == evt.node.id) {//全部

        if ('详情' == evt.data.action) {
            // 打开报价商品详情
            h3ui.widgets.Modal10.props.visible = true;
            // 加载报价商品数据
            let bizObjectId = evt.data.row.id;
            h3ui.models.t_quotation_goods.loadBO({bizObjectId: bizObjectId}).then();
        }
    } else if ('FormList14' == evt.node.id) {  // 创建报价,修改报价
        if ('删除' == evt.data.action) {
            h3ui.$confirm({
                title: '信息',
                content: '确认删除吗?',
                okText: '确定',
                okType: 'primary',
                cancelText: '取消',
                onOk() {
                    let items = h3ui.widgets[evt.node.id].props.dataSource.items;
                    let total = h3ui.widgets[evt.node.id].props.dataSource.total;
                    let id = evt.data.row.id;
                    for (let i = 0; i < items.length; i++) {
                        if (items[i].id == id) {
                            items.splice(i, 1);
                            total--;
                        }
                    }
                    dataSource.data.data = dataSource.data.data.filter(item => item.id != id);
                    dataSource.data.total--;
                    return;
                },
                onCancel() {
                    console.log('Cancel');
                    return;
                }
            })
        }
    }
    console.log(12121212121212);
}


// 询价商品澄清记录展开
function shrink(evt) {
    debugger;

    var timelineeId = "timelinee1";
    var openTimelineeButtonId = "Buttons36";
    if ('展开' == evt.data.name) {
        h3ui.widgets[timelineeId].props.visible.display = '';
        h3ui.widgets[openTimelineeButtonId].props.name = "收起";
    }

    if ('收起' == evt.data.name) {
        h3ui.widgets[openTimelineeButtonId].props.name = "展开";
        h3ui.widgets[timelineeId].props.visible.display = 'none';
    }
}


// 通过询价商品id查询澄清记录
function clarifyRecord(inquiryGoodsId) {

    var openTimelineeButtonId = "Buttons36";
    var timelineeId = "timelinee1";
    h3ui.widgets[openTimelineeButtonId].props.name = "展开";

    h3ui.widgets[timelineeId].props.visible.display = 'none';


    var param = {inquiryGoodsId: inquiryGoodsId};


    axiosService(quotationRoute.clarifyRecord, param).then(res => {
        if (res.success) {
            let clarifyRecord = res.data;
            h3ui.widgets[timelineeId].props.value = clarifyRecord;

        } else {
            h3ui.widgets[timelineeId].props.value = [];
        }
    })


}


// 单元格文本渲染
function cellRender(evt) {
    // 获取模型表格id
    let modelTableId = evt.node.parentId;
    // 获取表单id
    let formListId = h3ui.widgets[modelTableId].parentId;
    let {components, col, row, formatText} = evt.data;
    let value = row[col.key];
    let nodeId = evt.data.col.node.id;


    // 未参与报价中的字段 是否整单
    if ('ModelTableColumn6' == nodeId) {
        if ('是' == formatText) {
            components[0].props.fontColor = '#FF0000';
        }
    } else if (['ModelTableColumn248', 'ModelTableColumn113', 'ModelTableColumn172'].includes(nodeId)) {


        // 定标报价/参与次数
        var goods = row.inquiry_goods_id[0] || {};
        var countstr = (goods.quote_count || 0) + "/" + (goods.partake_count || 0);
        components[0].props.content = countstr;
    } else if ('ModelTableColumn193' == nodeId) {
        // 创建报价里 含税总计
        components[0].props.fontColor = '#FF0000';
    } else if ('ModelTableColumn50' == nodeId) {
        setQuotationGoodsStatus(components, value, formatText);
        // 未提交的报价状态
        components[0].props.text = '待提交';
    } else if (InquiryStyle.includes(nodeId)) {
        setInquiryStyle(components, formatText);
    } else if (GoodsStyle.includes(nodeId)) {

        setInquiryGoodsStyle(components, formatText);
    } else if (GoodsStatus.includes(nodeId)) {
        setInquiryGoodsStatus(components, formatText)
    } else if (QuotationStatus.includes(nodeId)) {
        setQuotationGoodsStatus(components, value, formatText);
    }

}


// 设置询价单样式
function setInquiryStyle(components, formatText) {
    components[0].props.fontColor = '#1890FF';
    components[0].props.fontSize = '14px';
    components[0].props.fontStyle = {
        textDecoration: 'underline'
    }
    components[0].props.content = 'R:' + formatText + '';
}

// 设置询价商品样式
function setInquiryGoodsStyle(components, formatText) {
    components[0].props.fontColor = '#1890FF';
    components[0].props.fontSize = '14px';
    components[0].props.fontStyle = {
        textDecoration: 'underline'
    }
    components[0].props.content = 'RG:' + formatText + '';
}

// 设置询价商品状态样式
function setInquiryGoodsStatus(components, formatText) {

    var color = InquiryGoodsStatusMap[formatText];
    components[0] = {
        type: 'Tag',
        props: {
            text: formatText,
            color
        }
    };
}

// 设置报价商品状态样式
function setQuotationGoodsStatus(components, value, formatText) {
    var color = quotationGoodsStatusArr[value];
    components[0] = {
        type: 'Tag',
        props: {
            text: formatText,
            color
        }
    };
}

// 设置询价商品澄清状态样式
function setClarifyStatus(components, formatText) {
    var color = '';
    switch (formatText) {
        case '未澄清':
            color = '#52C419';
            break;
        case '驻场待澄清':
            color = '#1890FF';
            break;
        case '供应商待澄清':
            color = '#F5222D';
            break;
    }
    components[0] = {
        type: 'Tag',
        props: {
            text: formatText,
            color
        }
    };
}


// 打开创建报价
function openCreateModal(evt) {

    var row = h3ui.widgets.FormList6.props.selectedRow;

    if (row.length == 0) {
        h3ui.$message.info("请勾选数据");
        return;
    }

    var row = JSON.parse(JSON.stringify(row));

    h3ui.$confirm({
        title: '确认报价吗？',
        okText: '确定',
        okType: 'primary',
        cancelText: '取消',
        onOk() {
            h3ui.widgets[quotationFormListId].props.sourceListId = "FormList6";
            h3ui.widgets.CustomModal6.props.title = "创建报价";

            h3ui.widgets.Label138.props.visible.display = 'none';
            h3ui.widgets.Label138.props.content = '含税总计:';
            h3ui.widgets.CustomModal6.props.visible = true;
            h3ui.widgets.CustomModal6.props.width = (0.95 * window.innerWidth);
            //显示一键设置
            h3ui.widgets.Buttons86.props.visible.display = "";
            h3ui.widgets[quotationFormListId].props.dataSource = {items: row, total: row.length};
            setEdit(quotationFormListId, updateQuotationKeyId, requiredQuotationKeyId);

            // 设置附件上传数量
            h3ui.widgets.Upload7.props.maxLength = 10;
            h3ui.widgets.Upload7.props.uploadSize = 10;
        },
        onCancel() {
            console.log('Cancel');
        }
    });

}


// 打开批量修改
function batchModifyQuotation() {
    debugger;

    var row = h3ui.widgets.FormList7.props.selectedRow;
    if (row.length == 0) {
        h3ui.$message.info("请勾选数据");
        return;
    }


    var row = JSON.parse(JSON.stringify(row));

    h3ui.widgets[quotationFormListId].props.sourceListId = "FormList7";
    h3ui.widgets.CustomModal6.props.title = "修改报价单";
    h3ui.widgets.Label138.props.visible.display = 'none';
    h3ui.widgets.Label138.props.content = '含税总计:';
    h3ui.widgets.CustomModal6.props.visible = true;
    h3ui.widgets.CustomModal6.props.width = (0.95 * window.innerWidth);
    //隐藏一键设置
    h3ui.widgets.Buttons86.props.visible.display = "none";
    h3ui.widgets[quotationFormListId].props.dataSource = {items: row, total: row.length};
    setEdit(quotationFormListId, updateQuotationKeyId, requiredQuotationKeyId);

    // 设置附件上传数量
    h3ui.widgets.Upload7.props.maxLength = 10;
    h3ui.widgets.Upload7.props.uploadSize = 10;

}

// 重设
function reset() {
    debugger;
    h3ui.widgets.Label138.props.visible.display = 'none';
    h3ui.widgets.Label138.props.content = '含税总计:';
    let sourceId = h3ui.widgets[quotationFormListId].props.sourceListId;
    if (sourceId) {
        let row = JSON.parse(JSON.stringify(h3ui.widgets[sourceId].props.selectedRow));
        h3ui.widgets[quotationFormListId].props.dataSource = {items: row, total: row.length};
        setEdit(quotationFormListId, updateQuotationKeyId, requiredQuotationKeyId);
    }

}


// 一键设置
function setup() {
    debugger;
    // 获取第一行要设置的数据信息
    let item = JSON.parse(JSON.stringify(h3ui.widgets[quotationFormListId].props.dataSource.items[0]));
    // 一键设置：报价有效期、发货地、货期
    h3ui.widgets[quotationFormListId].props.dataSource.items.map(e => {
        e.expire = item.expire;
        e.delivery = item.delivery;
        e.address = item.address;
    });
}


// 保存报价信息
function saveQuotation() {
    debugger;
    // 获取数据
    let items = h3ui.widgets[quotationFormListId].props.dataSource.items;
    let param = JSON.parse(JSON.stringify(items));
    param.map(item => {
        item.inquiry_goods_id = item.inquiry_goods_id[0].id;
        item.maximum = item.num;
        item.min_order = item.num;
        // 如果是新上传的附件，取attachment.response.data
        for (let i = 0; i < item.attachment.length; i++) {
            if (item.attachment[i].response) {
                item.attachment[i] = item.attachment[i].response.data;
            }
        }
        // listBO查询出来的逻辑控件是0和1，使用updateBO更新时需要传true和false
        item.auto_quotation = item.auto_quotation == '0' ? false : true;
        item.picketage = item.auto_quotation == '0' ? false : true;
        item.virtual_vendor = item.auto_quotation == '0' ? false : true;
    });

    axiosService(quotationRoute.updateQuotation, param).then(res => {
        debugger;
        if (res.success) {
            h3ui.$message.info('成功');
            // 关闭对话框
            h3ui.widgets.CustomModal6.props.visible = false;
            // 清理缓存
            h3ui.widgets.Label138.props.visible.display = 'none';
            h3ui.widgets.Label138.props.content = '含税总计:';

            reloadList("FormList6");
        }
    });
}


// 列表行失焦事件
function formListRowBlur(evt) {
    debugger;
    if ('pretax_price' == evt.data.col.key) {
        let pretaxPrice = evt.data.row.pretax_price;
        let num = evt.data.row.num;
        let taxRate = evt.data.row.tax_rate;
        let taxRateFreight = evt.data.row.tax_rate_freight;
        let pretaxFreight = evt.data.row.pretax_freight;
        let param = {
            pretaxPrice: pretaxPrice,
            num: num,
            taxRate: taxRate,
            taxRateFreight: taxRateFreight,
            pretaxFreight: pretaxFreight
        }
        // 请求自定义服务，计算金额

        axiosService(quotationRoute.amountCalculation, param).then(res => {
            debugger;
            if (res.data && res.success) {
                // 金额赋值
                evt.data.row.price = res.data.price;
                evt.data.row.freight = res.data.freight;
                evt.data.row.tax_payable_freight = res.data.tax_payable_freight;
                evt.data.row.tax_payable = res.data.tax_payable;
                evt.data.row.total = res.data.total;
                evt.data.row.pretax_total = res.data.pretax_total;
                evt.data.row.amount = res.data.amount;
                evt.data.row.pretax_amount = res.data.pretax_amount;
                // 计算含税总计
                let total = 0;
                let length = h3ui.widgets[evt.node.id].props.dataSource.items.length;
                if (length == 1) {
                    total = h3ui.widgets[evt.node.id].props.dataSource.items[0].total;
                } else {
                    for (let item of h3ui.widgets[evt.node.id].props.dataSource.items) {
                        total += (item.total == undefined || item.total == null) ? 0 : item.total
                    }
                }
                // 显示含税总计
                let amountId = '';
                if ('FormList14' == evt.node.id) {
                    amountId = 'Label138';
                }
                h3ui.widgets[amountId].props.visible.display = '';
                h3ui.widgets[amountId].props.content = '含税总计：' + total + ''
            }
        });
    }
}


// 设置表格编辑权限
function setEdit(id, keyId, requiredId) {
    // 关闭列表编辑权限
    h3ui.widgets[id].props.editing = false;
    // 关闭行编辑权限
    h3ui.widgets[id].props.dataSource.rowsStatus = {};
    h3ui.widgets[id].props.dataSource.colsStatus = {};
    // 开启表单可编辑
    openEditStatus(h3ui.widgets[id].props.bindingModel.schemaCode, id, keyId, requiredId);
}

/**
 * 开启对应行中的列编辑状态
 * id 表单对应的id值
 * items 表单数据
 * row 当前点击的行信息
 * colKey 当前点击的列key 其值对应为模型中的字段编码
 **/
function openEditStatus(schemaCode, id, keyId, requiredId) {
    // 开启列表的编辑权限
    debugger;
    h3ui.widgets[id].props.editing = true;
    // 获取模型字段列表
    let ps = h3ui.models[schemaCode].schema.properties;

    let colsStatus = {};
    for (let p of ps) {
        // 开启当前列数据权限
        colsStatus = Object.assign(colsStatus, {
            [p.code]: {
                writable: keyId.includes(p.code),
                required: requiredId.includes(p.code)
            }
        })
    }

    h3ui.widgets[id].props.dataSource.colsStatus = colsStatus;
}


// 批量提交
function batchCommit() {
    debugger;
    let listId = "FormList7";
    var list = h3ui.widgets[listId];
    let length = list.props.selectedRowKeys.length;
    if (length == 0) {
        h3ui.$info({title: "请选择数据行"});
        return false;
    }
    for (let item of list.props.selectedRow) {
        if (item.pretax_price == undefined || item.pretax_price == null) {
            h3ui.$info({title: "请勿勾选报价状态为新建的商品"});
            h3ui.$error({
                title: '错误提示',
                content: '请勿勾选报价状态为新建的商品',
            });
            return false;
        }
    }
    h3ui.$confirm({
        title: '确定提交报价?',
        onOk() {
            let quotationIds = list.props.selectedRowKeys;

            //选择询价单id

            var inquiryIds = new Array();
            for (let selectedRowElement of list.props.selectedRow) {
                let params={
                    inquiryId:selectedRowElement.inquiryId,
                    quotationId:selectedRowElement.quotationId,
                }
                inquiryIds.push(params)
            }
            // 请求自定义服务
            axiosService(quotationRoute.batchCommit, inquiryIds).then(res => {
                debugger;
                if (res.success && res.data) {
                    h3ui.$message.success('提交成功');
                    // 刷新页面
                    reloadList(listId);
                }
            })
        }
    });
}


// 删除询价单
function deleteQuotation() {
    let listId = "FormList7";
    var list = h3ui.widgets[listId];
    let length = list.props.selectedRowKeys.length;
    if (length == 0) {
        h3ui.$message.info('请选择要删除的数据行');
    }
    h3ui.$confirm({
        title: '确认删除吗?',
        okText: '确定',
        okType: 'primary',
        cancelText: '取消',
        onOk() {
            h3ui.models.t_quotation_goods.batchDeleteBO({bizObjectIds: list.props.selectedRowKeys}).then(() => {
                h3ui.$message.info('成功');
                // 刷新页面
                reloadList(listId);
            });
        },
        onCancel() {
            console.log('Cancel');
        }
    })
}


// 再次报价
function counterPrice() {
    debugger;
    let quotationIdList = [h3ui.models.t_quotation_goods.item.id];
    let pretaxPrice = h3ui.models.t_quotation_goods.item.pretax_price;
    let param = {quotationIdList, pretaxPrice};

    axiosService(quotationRoute.counterPrice, param).then(res => {
        if (res.success) {
            // 关闭对话框
            h3ui.widgets.Modal11.props.visible = false;
            h3ui.$message.success('成功');
            reloadList("FormList10");
        } else {
            h3ui.$message.error('失败');
        }
    });
}


//未提交表加载事件
function inventedQuotationNew(evt) {

    let conds = [];
    //价格大于0
    conds.push({field: "pretax_price", operator: Operator.GT, value: 0});

    customConditionLoad(evt, conds);
}


//自定义虚拟供应商报价商品加载事件
function custInventedQuotedList(evt) {
    customConditionLoad(evt, [], "inventedQuotedList");
}


// 导出
function exportQuotation(evt) {
    debugger;
    let formlistId = '';//列表ID
    //未参与报价导出按钮
    if(evt.node.id == 'Buttons15' ){
        formlistId = 'FormList4';
    }else if(evt.node.id == 'Buttons35'){
        formlistId = 'FormList6';
    }
    let length = h3ui.widgets[formlistId].props.selectedRowKeys.length;
    if (length == 0) {
        h3ui.$message.warn('请选择要导出的数据');
        return false;
    }
    // 显示对话框
    h3ui.widgets.RadioGroup1.props.value = 'xlsx';
    h3ui.widgets.Modal12.props.visible = true;
    let buttenId = evt.node.id;
    localStorage.setItem("buttenId",buttenId);//放入缓存
}

// 确认导出
function confirmExportQuotationGoodstWithAll(evt) {
    debugger
    let buttenId = localStorage.getItem("buttenId");//取数据
    localStorage.removeItem("buttenId");//清缓存
    let formlistId = '';//列表ID
    let serviceId = 'exportInvented';//导出接口
    let exportType='';
    //未参与报价导出按钮
    if(buttenId == 'Buttons15' ){
        formlistId = 'FormList4';
        exportType='not_involved';
    }else if(buttenId == 'Buttons35'){
        formlistId = 'FormList6';
        exportType='notQuoted';
    }
    if (!h3ui.widgets.RadioGroup1.props.value) {
        h3ui.$message.warn('请选择要导出的格式');
        return false;
    }

    // 关闭对话框
    h3ui.widgets.Modal12.props.visible = false;
    // 设置要导出的文件
    // 获取要导出的数据
    let rowKeys = h3ui.widgets[formlistId].props.selectedRowKeys;
    // 获取到导出的格式
    let type = h3ui.widgets.RadioGroup1.props.value;
    let param = {
        data:{ids:rowKeys,fileType:type,exportType:exportType},
        schemaCode:h3ui.widgets[formlistId].props.bindingModel.domainCode
    }
    h3ui.services[serviceId](param).then(res => {
        if (res.success) {
            h3ui.widgets.gmNoticeBar1.props.visible = true;
        }else{
            h3ui.$message.warn('暂无数据');
        }
    })
}
